%   Copyright (c) [2023] [423109070325付志峰]
%   [春天的高等数学代码库] is licensed under Mulan PSL v2.
%   You can use this software according to the terms and conditions of the Mulan PSL v2. 
%   You may obtain a copy of Mulan PSL v2 at:
%            http://license.coscl.org.cn/MulanPSL2 
%   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
%   See the Mulan PSL v2 for more details. 
format long
%左右端点值
x_1=0;
x_2=5;
%定义求解函数
syms x
y=(x^2)-2
%二分法求解
for i=1:100
    x_0=(x_1+x_2)/2;
    y_0=subs(y,x_0);
        if y_0>0
            x_2=x_0;
        else
            x_1=x_0;
        end
end
%输出
x_0;
disp(x_0)




